<?php
class IndexAction extends HomeAction {
    public function index(){
    	$this->assign("inIndex", true);
    
    	$Book = D("Book");
    	
    	$newBookList = $Book->order('addTime')->limit(10)->select();
        $this->assign("newBookList",$newBookList);
    	$todayRank = $Book->order('todayClick')->limit(10)->select();
        $this->assign("todayRank",$todayRank);
    	$weekRank = $Book->order('weekClick')->limit(10)->select();
        $this->assign("weekRank",$weekRank);
    	$monthRank = $Book->order('monthClick')->limit(10)->select();
        $this->assign("monthRank",$monthRank);
    	$totalRank = $Book->order('click')->limit(10)->select();
        $this->assign("totalRank",$totalRank);
        
        $recommendFlag = C('RECOMMEND_HOT');
    	$hotRecomend = $Book->where("recommend&{$recommendFlag}={$recommendFlag}")->order('sortIndex')->limit(2)->select();
        $this->assign("hotRecomend",$hotRecomend);
        $recommendFlag = C('RECOMMEND_TOP');
    	$topRecomend = $Book->where("recommend&{$recommendFlag}={$recommendFlag}")->order('sortIndex')->limit(2)->select();
        $this->assign("topRecomend",$topRecomend);
        $recommendFlag = C('RECOMMEND_FAME');
    	$fameRecomend = $Book->where("recommend&{$recommendFlag}={$recommendFlag}")->order('sortIndex')->limit(2)->select();
        $this->assign("fameRecomend",$fameRecomend);
        $recommendFlag = C('RECOMMEND_ART');
    	$artRecomend = $Book->where("recommend&{$recommendFlag}={$recommendFlag}")->order('sortIndex')->limit(2)->select();
        $this->assign("artRecomend",$artRecomend);
        
        $catList = D("Catalog")->order('sortIndex')->select();
        $catRecommend = array();
        $recommendPicFlag = C('RECOMMEND_CATPIC');
        $recommendListFlag = C('RECOMMEND_CATLIST');
        foreach($catList as $cat){
        	$cat["picRecommend"] = $Book->where("catId={$cat["id"]} and recommend&{$recommendPicFlag}={$recommendPicFlag}")->order('sortIndex')->find();
        	$cat["listRecommend"] = $Book->where("catId={$cat["id"]} and recommend&{$recommendListFlag}={$recommendListFlag}")->order('sortIndex')->limit(4)->select();
        	$catRecommend[] = $cat;
        }
        $this->assign("catRecommend",$catRecommend);
        
        $dbPre = C("DB_PREFIX");
        $lastUpdateList = $Book->field('c.*, b.bookName')->table($dbPre."bookContent c")
        	->join(C("DB_PREFIX")."book b on b.bookId=c.id")
        	->order("c.addTime desc")->limit(20)->select();
    	
    	$this->display();
    }
}
